//
//  StatusCellBottomView.swift
//  WeiBo_Private
//
//  Created by Yangperlove on 16/1/18.
//  Copyright © 2016年 Yangperlove. All rights reserved.
//

import UIKit

class StatusCellBottomView: UIView {

    
    override init(frame: CGRect) {
        super.init(frame: frame)
//        backgroundColor = UIColor.yellowColor()
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        addSubview(retweetedBtn)
        addSubview(commentBtn)
        addSubview(likeBtn)
        addSubview(seperateLine)
        
        //添加约束
        addConstraint()
        
        //原因: 没有添加到父视图上
        //因为在构造方法中还不能确定视图的frame,所以不能使用视图的frame,结果都是0
        let sepView1 = lineView()
        
        let sepView2 = lineView()
        addSubview(sepView1)
        addSubview(sepView2)
        //设置约束
        
        let w: CGFloat = 0.5
        let scale: CGFloat = 0.4
        
        sepView1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(scale)
            make.width.equalTo(w)
        }
        
        sepView2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(scale)
            make.width.equalTo(w)
        }
        
        seperateLine.snp_makeConstraints { (make) -> Void in
            make.top.left.right.equalTo(self)
            make.height.equalTo(0.5)
        }
        
        commentBtn.addTarget(self, action: "commentBtnDidClick", forControlEvents: .TouchUpInside)
    }
    
    func commentBtnDidClick() {
        navController()?.pushViewController(TempViewController(), animated: true)
    }
    
     //添加约束
    func addConstraint() {
        retweetedBtn.snp_makeConstraints { (make) -> Void in
            make.left.top.bottom.equalTo(self)
        }
        
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedBtn.snp_right)
            make.top.bottom.equalTo(retweetedBtn)
            make.size.equalTo(retweetedBtn)
        }
        
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentBtn.snp_right)
            make.top.bottom.equalTo(commentBtn)
            make.size.equalTo(commentBtn)
            make.right.equalTo(self)
        }
    }
    
    //添加竖线
    func lineView() -> UIView {
        let line = UIView()
        line.backgroundColor = UIColor.lightGrayColor()
        
        return line
    }
    
    //懒加载子控件
    //转发微博的按钮
    private lazy var retweetedBtn: UIButton = UIButton(backImageName: nil, stretchable: false, imageName: "timeline_icon_retweet", title: "评论", fontSize: 10, titleColor: UIColor.darkGrayColor())
    // 评论
    lazy var commentBtn: UIButton = UIButton(backImageName: nil, stretchable: false, imageName: "timeline_icon_comment", title: "评论", fontSize: 10, titleColor: UIColor.darkGrayColor())
    //点赞
    private lazy var likeBtn: UIButton = UIButton(backImageName: nil, stretchable: false, imageName: "timeline_icon_unlike", title: "点赞", fontSize: 10, titleColor: UIColor.darkGrayColor())
    
    lazy var seperateLine: UIView = {
        let line = UIView()
        line.backgroundColor = UIColor(white: 0.8, alpha: 0.6)
        return line
    }()
    
}
